package freecomm.fileexplorer;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

public class optionMenu extends PopupWindow
{
    private GridView optionMenuGridView;
    private LinearLayout mLayout;
    public optionMenu(Context context,OnItemClickListener bodyClick,int aniTabMenu){
        super(context);
        mLayout = new LinearLayout(context);  
        mLayout.setOrientation(LinearLayout.VERTICAL);  
        optionMenuGridView = new GridView(context);  
        optionMenuGridView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));  
        optionMenuGridView.setSelector(new ColorDrawable(Color.TRANSPARENT));//选中的时候为透明色  
        optionMenuGridView.setNumColumns(4);  
        optionMenuGridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);  
        optionMenuGridView.setVerticalSpacing(10);  
        optionMenuGridView.setHorizontalSpacing(10);  
        optionMenuGridView.setPadding(10, 10, 10, 10);  
        optionMenuGridView.setGravity(Gravity.CENTER);  
        optionMenuGridView.setOnItemClickListener(bodyClick);  
        mLayout.addView(optionMenuGridView);  
    }
    static public class OptionMenuAdapter extends BaseAdapter {  
        private Context mContext;  
        private int fontColor,fontSize;  
        private String[] texts;  
        private int[] resID;  
        public OptionMenuAdapter(Context context, String[] texts,int[] resID, int fontSize,int fontColor)   
        {  
            this.mContext = context;  
            this.fontColor = fontColor;  
            this.texts = texts;  
            this.fontSize=fontSize;  
            this.resID=resID;  
        }  
        public int getCount() {  
            return texts.length;  
        }  
        public Object getItem(int position) {  
              
            return makeMenyBody(position);  
        }  
        public long getItemId(int position) {  
            return position;  
        }  
        private LinearLayout makeMenyBody(int position)  
        {  
            LinearLayout result=new LinearLayout(this.mContext);  
            result.setOrientation(LinearLayout.VERTICAL);  
            result.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);     
            result.setPadding(10, 10, 10, 10);  
              
            TextView text = new TextView(this.mContext);  
            text.setText(texts[position]);  
            text.setTextSize(fontSize);  
            text.setTextColor(fontColor);  
            text.setGravity(Gravity.CENTER);  
            text.setPadding(5, 5, 5, 5);  
            ImageView img=new ImageView(this.mContext);  
            img.setBackgroundResource(resID[position]);  
            result.addView(img,new LinearLayout.LayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT))); 
            result.addView(text);  
            return result;  
        }           
        public View getView(int position, View convertView, ViewGroup parent) {  
            return makeMenyBody(position);  
        }  
    }  
}
